package com.bdqn.service;

import com.bdqn.mapper.SysUserMapper;
import com.bdqn.pojo.MyBatisUtil;
import com.bdqn.pojo.SysUser;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class SysUserServiceImpl implements SysUserService{

    private static final Logger logger= LogManager.getLogger(SysUserServiceImpl.class);

    @Override
    public SysUser login(String account, String password) {
        if(account == null || password==null){   //参数错误
            logger.debug("参数错误");
            return null;
        }
        SysUser sysUser=null;
        SqlSession sqlSession=null;
        try {
            sqlSession= MyBatisUtil.createSqlSession();
            sysUser=sqlSession.getMapper(SysUserMapper.class).getByAccount(account);
            if(sysUser==null){ //账号不存在
                logger.debug("账号不存在");
                return null;
            }
            if (!password.equals(sysUser.getPassword())){ //密码不匹配
                logger.debug("密码不匹配");
                return null;
            }
        }catch (Exception e){
            logger.error(e.getMessage());
        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
        return sysUser;
    }
}
